package com.cl.it;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class CodeGeneratorMain {

    // 处理 all 情况
    protected static List<String> getTables(String tables) {
        return "all".equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
    }

    public static void main(String[] args) {
        DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig.
                Builder("jdbc:mysql://127.0.0.1:3306/quick-facts?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai", "root", "kehui.1225");
        FastAutoGenerator.create(DATA_SOURCE_CONFIG)
                .globalConfig(builder -> {
                    builder.author("kehui") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("/Users/kehui/IdeaProjects/access-indirect/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.access.helper") // 设置父包名
                            .moduleName("mbg") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "/Users/kehui/IdeaProjects/access-indirect/src/main/java/com/cl/it/mbg/mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("company",
                                    "news",
                                    "qcc_business_info",
                                    "qcc_company_info",
                                    "qcc_financing_info",
                                    "itjuzi_business_change_info",
                                    "itjuzi_business_info",
                                    "qcc_job_info",
                                    "qcc_notice_info",
                                    "qcc_tender_info",
                                    "qcc_touzi_info",
                                    "qcc_wenshu_info"
                            ) // 设置需要生成的表名
                            .addTablePrefix("t_", "c_"); // 设置过滤表前缀
                })
                .templateEngine(new VelocityTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();



    }
}
